using System;
using System.Collections.Generic;
using System.Text;

using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;
using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling.Diagrams;
using Microsoft.VisualStudio.Modeling;

namespace Evaluant.EussDSL
{
    /// <summary>
    /// Additional behavior of the shape of an entity in order to detect inheritance relations.
    /// </summary>
    public partial class EntityShape
    {
        public override void OnShapeInserted()
        {
            base.OnShapeInserted();

            using (Transaction t = this.Store.TransactionManager.BeginTransaction("Try to connect the shape with others via inheritance"))
            {
                if (this.ModelElement != null)
                {
                    InheritanceDetector.DetectAndShow((Entity)this.ModelElement);
                }
                
                if (!GlobalData.isDiagramFilePresent && GlobalData.numberOfEntities > 0)
                {
                    GlobalData.numberOfEntities--;
                    GlobalData.lse.Add(this);

                    if (GlobalData.numberOfEntities == 0)
                    {
                        this.Diagram.AutoLayoutShapeElements(GlobalData.lse);
                        GlobalData.isDiagramFilePresent = true;
                    }
                }

                t.Commit();
            }
        }
    }
}
